# @Time : 2021/3/19 16:13
# @Author : Li Kunlun
# @Description : 求解非支配解集（在非支配解集中的元素都有其可取之处，不存在完全优于它的其他解）
import numpy as np
import pandas as pd

d = {
    'A': [20, 2.2],
    'B': [60, 4.4],
    'C': [65, 3.5],
    'D': [15, 4.4],
    'E': [55, 4.5],
    'F': [50, 1.8],
    'G': [80, 4.0],
    'H': [25, 4.6]
}
df = pd.DataFrame(data=d).T
data_labels = list(df.index)
data_array = np.array(df).T


def solve(sol_index):
    sol = data_array[:, sol_index]
    obj1_not_worse = np.where(sol[0] >= data_array[0, :])[0]
    obj2_not_worse = np.where(sol[1] >= data_array[1, :])[0]
    not_worse_candidates = set.intersection(set(obj1_not_worse), set(obj2_not_worse))

    obj1_better = np.where(sol[0] > data_array[0, :])[0]
    obj2_better = np.where(sol[1] > data_array[1, :])[0]
    better_candidates = set.intersection(set(obj1_better), set(obj2_better))

    dominating_solution = list(set.intersection(not_worse_candidates, better_candidates))
    if len(dominating_solution) == 0:
        return True
    else:
        return False


dominating_set = []
for k in range(data_array.shape[1]):
    if solve(k):
        dominating_set.append(data_labels[k])
# 输出：['A', 'D', 'F']
print(dominating_set)
